import React, {useEffect, useState} from 'react';
import './index.css'
import http from "../../../util/http";
import {useNavigate} from "react-router-dom";

function Headlines(props) {
    let navigate = useNavigate();
    //初始化文章变量
    const [word, setWord] = useState({
        title: "",
        abstract: "",
        docId: -1
    });

    useEffect(() => {
        http.doPost('/doc/getdoc', {category: 256, pageNum: 1, pageSize: 1}).then(res => {
            if (res.status === 200) {
                const element = res.data.list[0];
                setWord({
                    title: element.docSubject,
                    abstract: element.docContent,
                    docId: element.id
                })
            }
        })
    }, [])

    function openUrl(docId) {
        if (docId && docId !== "") {
            navigate('/portal/details', {
                state: {docId, page: "home", text: ""}
            });
        }
    }

    return (
        <div className="headlines-main">
            <div className="headlines-title">{word.title}</div>
            <div className="headlines-abstract" onClick={() => openUrl(word.docId)}>本站讯 {word.abstract}</div>
            <div className="headlines-separated"/>
        </div>
    );
}

export default Headlines;